package com.wiloon.monitor.sync;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;

/**
 * Created by roy on 12/11/16;
 */
public class Icon {
    private static Logger logger = LoggerFactory.getLogger(Icon.class);
    private String path;
    private static File file = new File("/home/roy/apps/qq-monitor/status-sync");

    public Icon() {

    }

    public String getPath() {
        return path;
    }

    public void setPath(String path) {
        if (this.path == null || !this.path.equals(path)) {
            this.path = path;
            serialize();
        }
    }

    private void serialize() {
        try {
            FileOutputStream fileOutputStream = new FileOutputStream(file);
            PrintWriter pw = new PrintWriter(fileOutputStream);
            pw.write(path.toCharArray());
            pw.flush();
            pw.close();
            logger.info("update sync file:{}", path);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }
}
